﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using Qtech.Reports.Atendimento.Services;
using CeA.Reports.Atendimento.DataAccess.DTO;
using CeA.Reports.Atendimento.Web.Helpers;

namespace CeA.Reports.Atendimento.Web.admin {
    public partial class planejamentocadastro : System.Web.UI.Page {
        protected void Page_Init(object sender, EventArgs e) {
            cmdVoltar.Click += new EventHandler(cmdVoltar_Click);
        }
        
        
        protected void Page_Load(object sender, EventArgs e) {
            if (PreviousPage != null) {
                this.CodigoLoja = PreviousPage.CodigoLoja;                
                this.PageMode = PreviousPage.PageMode;
            }

            if (Request.QueryString["loja"] != null) {
                this.CodigoLoja = Convert.ToInt32(Request.QueryString["loja"]);
                this.PageMode = "PLANEJAMENTO";
            }

            if (this.CodigoLoja == 0)
                Server.Transfer("/admin/loja.aspx?tag=plan");
            
            if (!Page.IsPostBack)
                carregar();
        }

        protected void cmdVoltar_Click(object sender, EventArgs e) {
            NavigationHelper.RefererRedirect("/admin/loja.aspx?tag=plan");
        }

        private void carregar() {
            int lojaId = this.CodigoLoja;
            if (lojaId > 0) {
                LojaDTO ds = CadastroFacade.GetLoja(lojaId);
                this.CodigoBranchno = ds.QmaticInfo.BranchNumber;
                txtSigla.Text = ds.Sigla;
                txtNome.Text = ds.Nome;
            }
        }



        #region -- Page Properties --------------------------------------------


        public int CodigoBranchno
        {
            get {
                if (ViewState["m_codigoBranchno"] != null)
                    return Convert.ToInt32(ViewState["m_codigoBranchno"]);
                return 0;
            }
            set {
                ViewState.Add("m_codigoBranchno", value);
            }
        }


        public int CodigoLoja {
            get {
                if (ViewState["m_codigoLoja"] != null)
                    return Convert.ToInt32(ViewState["m_codigoLoja"]);
                return 0;
            }
            set {
                ViewState.Add("m_codigoLoja", value);
            }
        }

        public string PageMode {
            get {
                if (ViewState["m_pageMode"] != null)
                    return Convert.ToString(ViewState["m_pageMode"]);
                return "PLANEJAMENTO";
            }
            set {
                ViewState.Add("m_pageMode", value);
            }
        }


        #endregion
    }
}
